package com.kd.juhaowan.ui;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.kd.juhaowan.R;
import com.kd.juhaowan.http.api.RealNameApi;
import com.kd.juhaowan.http.model.HttpData;
import com.kd.juhaowan.http.model.MineResult;
import com.hjq.http.EasyHttp;
import com.hjq.http.listener.HttpCallbackProxy;
import com.hjq.toast.ToastUtils;

import butterknife.BindView;
import butterknife.OnClick;

public class SettingRealnameActivity extends BaseActivity {





    @BindView(R.id.activity_title)
    TextView titleView;
    @BindView(R.id.login_confirm)
    TextView confirmView;
    @BindView(R.id.realname_already_layout)
    LinearLayout alreadyLayout;
    @BindView(R.id.realname_no_layout)
    LinearLayout realnameLayout;
    @BindView(R.id.realname_name_text)
    TextView nameText;
    @BindView(R.id.realname_idcard_text)
    TextView idcardText;
    @BindView(R.id.realname_name)
    EditText nameEdit;
    @BindView(R.id.realname_idcard)
    EditText idcardEdit;





    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        titleView.setText("实名认证");
        MineResult mineInfo = (MineResult)getIntent().getSerializableExtra("user");
        if(TextUtils.isEmpty(mineInfo.getId_card())){
            realnameLayout.setVisibility(View.VISIBLE);
            alreadyLayout.setVisibility(View.GONE);
            confirmView.setVisibility(View.VISIBLE);
        }else{
            realnameLayout.setVisibility(View.GONE);
            alreadyLayout.setVisibility(View.VISIBLE);
            nameText.setText(mineInfo.getFull_name());
            idcardText.setText(mineInfo.getId_card());
            confirmView.setVisibility(View.GONE);
        }
//        setContentView(R.layout.activity_account_login);

    }

    @Override
    protected void reInitDate() {

    }

    @OnClick(R.id.actvity_back)
    public void onBackClick(){
        finish();
    }
    @OnClick(R.id.login_confirm)
    public void onConfirmClick(){
        String name = nameEdit.getText().toString().trim();
        String id = idcardEdit.getText().toString().trim();
        if(TextUtils.isEmpty(name)){
            ToastUtils.show("请输入真实姓名");
        }else if(TextUtils.isEmpty(id)){
            ToastUtils.show("请输入身份证号");
        }else {
            EasyHttp.post(this).api(new RealNameApi(name,id)).request(new HttpCallbackProxy<HttpData<MineResult>>(this){
                @Override
                public void onHttpSuccess(HttpData<MineResult> result, boolean cache) {
                    super.onHttpSuccess(result, cache);
                    AccountManagerActivity.needRefresh=true;
                    ToastUtils.show("实名认证成功");
                    finish();
                }
            });
        }
    }
    @Override
    protected int getViewLayoutResourceId() {
        return R.layout.activity_realname;
    }




}
